﻿using System;
using System.Web.Mvc;
using Xenta.Utils;
using Xenta.Attributes;
using Xenta.Web.Controllers;

namespace Xenta.Web.Areas.System.Controllers
{
    [Authenticate, InRole("ADMIN")]
    public sealed class ConfigurationController : ExtController
    {
        [HttpGet, RestoreState]
        public ActionResult Index()
        {
            var m = Svc.ProcessOperation("GetConfigParamDictionary");
            return View(m);
        }

        [HttpPost, PersistState]
        public ActionResult Set(string key, string value)
        {
            try
            {
                Svc.ProcessOperation("SetConfigParam", new
                {
                    Key = key,
                    Value = value
                });
            }
            catch(Exception ex)
            {
                ModelState.AddModelError("API", ex);
            }
            return RedirectToAction(Loc.Act("Index"));
        }
    }
}
